//
// Created by v on 2021/5/7.
//

#include <iostream>

std::string caesar_crypto(std::string &data, int k)
{
    std::string result;
    for (int i = 0; i < data.length(); i++)
    {
        if (data[i] >= 'a' && data[i] <= 'z')
        {
            if (data[i] + k > 'z')
            {
                result.append(1, data[i] + k - 'z' + 'a');
            }
            else
            {
                result.append(1, data[i] + k);
            }
        }
        else if (data[i] >= 'A' && data[i] <= 'Z')
        {
            if (data[i] + k > 'Z')
            {
                result.append(1, data[i] + k - 'Z' + 'A');
            }
            else
            {
                result.append(1, data[i] + k);
            }
        }
        else
        {
            result.append(1, data[i]);
        }
    }
    return result;
}

int main(int argc, char **args)
{
    if (argc < 2)
    {
        printf("%s [data]\n", args[0]);
        return -1;
    }
    std::string origin(args[1]);
    std::string crypto = caesar_crypto(origin, 2);

    printf("origin: %s\n", origin.c_str());
    printf("crypto: %s\n", crypto.c_str());
    return 0;
}
